//
//  ZQStatusFrame.m
//  柳州微博
//
//  Created by Apple_Lzzy40 on 16/10/19.
//  Copyright © 2016年 Apple_Lzzy40. All rights reserved.
//

#import "ZQStatusFrame.h"
#import "ZQUser.h"
#import "NSString+ZQNSString.h"
#import "ZQStatusPhotosView.h"
#import "ZQIconView.h" 
@implementation ZQStatusFrame
-(void)setStatus:(ZQStatus *)status
{
    _status=status;
    ZQUser * user = status.user;
    
    //cell的宽度
    CGFloat cellW=[UIScreen mainScreen].bounds.size.width;
    /**头像*/
    CGFloat iconX=ZQStatusCellBorderW;
    CGFloat iconY=ZQStatusCellBorderW;
    CGFloat iconW=40;
    CGFloat iconH=40;
    _iconViewFrame=CGRectMake(iconX, iconY, iconW, iconH);
    
    /** 昵称 */
    CGFloat nameX=CGRectGetMaxX(_iconViewFrame) +ZQStatusCellBorderW;
    CGFloat nameY=iconY;
    // 获得字符串的尺寸
//      CGSize nameSize =[self sizeWithText:user.name font:ZQStatusCellNameFont];
    CGSize nameSize =[user.name sizeWithText:ZQStatusCellNameFont ];
//    CGSize nameSize =[user.n];
    _nameLabelFrame=CGRectMake(nameX, nameY, nameSize.width, nameSize.height);

    /** 会员图标 */
    if (user.isVip) {
        CGFloat vipX=CGRectGetMaxX(_nameLabelFrame)+ZQStatusCellBorderW;
        CGFloat vipY=nameY;
        CGFloat vipW=15;
        CGFloat vipH=nameSize.height;
        _vipViewFrame=CGRectMake(vipX, vipY, vipW, vipH);
    }
    
    /** 时间 */
    CGFloat timeX=nameX;
    CGFloat timeY= CGRectGetMaxY(_nameLabelFrame)+ ZQStatusCellBorderWL;
    // 获得字符串的尺寸
//    CGSize timeSize=[self sizeWithText:status.created_at font:ZQStatusCellTimeFont];
    CGSize timeSize=[status.created_at sizeWithText:ZQStatusCellTimeFont];
    _timeLabelFrame=CGRectMake(timeX, timeY, timeSize.width, timeSize.height);
    
    /** 来源 */
    CGFloat sourceX=CGRectGetMaxX(self.timeLabelFrame)+ZQStatusCellBorderWL;
    CGFloat sourceY=timeY;
    // 获得字符串的尺寸
    //CGSize sourceSize=[self sizeWithText:status.source font:ZQStatusCellSourceFont];
    CGSize sourceSize=[status.source sizeWithText:ZQStatusCellSourceFont];
    _sourceLabelFrame=CGRectMake(sourceX, sourceY, sourceSize.width, sourceSize.height);
    
    /** 正文 */
    CGFloat contentLanelX=iconX;
    CGFloat contentLanelY=CGRectGetMaxY(self.iconViewFrame);
    CGFloat contentLableW = cellW - 2 * ZQStatusCellBorderWL;
//    CGSize contentSize=[self sizeWithText:_status.text font:ZQStatusCellContentFont maxW:contentLableW];
    CGSize contentSize=[_status.text sizeWithText:ZQStatusCellContentFont maxW:contentLableW];

    self.contentLabelFrame=CGRectMake(contentLanelX, contentLanelY, contentSize.width, contentSize.height);
    
    /** 配图 */
    CGFloat originalH=0;
    //图片张数
    NSInteger photosCount =status.pic_urls.count;
    if (photosCount) {//有配图
        CGFloat  picturesX =contentLanelX;
        CGFloat  picturesY = CGRectGetMaxY(self.contentLabelFrame)+ZQStatusCellBorderWL;
        CGFloat  picturesW=[ZQStatusPhotosView photosviewSizeWithCount:photosCount].width;
        CGFloat  picturesH=[ZQStatusPhotosView photosviewSizeWithCount:photosCount].height;
        
        self.photosViewFrame=CGRectMake(picturesX, picturesY, picturesW, picturesH);
        originalH=CGRectGetMaxY(self.photosViewFrame)+ZQStatusCellBorderWL;
    }else
    {
        originalH=CGRectGetMaxY(self.contentLabelFrame)+ZQStatusCellBorderWL;
    }

    /** 原创微博的容器 */
    CGFloat originalX=0;
    CGFloat originalY=0;
    CGFloat originalW=cellW;
    self.originalViewFrame=CGRectMake(originalX, originalY, originalW, originalH);
    self.cellHeight = CGRectGetMaxY(self.originalViewFrame);
    
    /** 转发微博容器 */
    CGFloat toolbarY=0;
    if (status.retweeted_status) {
        //有转发微博
        ZQStatus * retweeted_status=status.retweeted_status;
//        ZQUser * retweeted_status_user=retweeted_status.user;
        
        /** 转发微博正文 */
        CGFloat retweetedContentX=ZQStatusCellBorderW;
        CGFloat retweetedContentY=ZQStatusCellBorderW;
        CGFloat retweetedContentW = cellW - 2 * ZQStatusCellBorderWL;
        
//        CGSize retweetedContentSize=[self sizeWithText:retweeted_status.text font:ZQStatusCellContentFont maxW:retweetedContentW];
         CGSize retweetedContentSize=[retweeted_status.text sizeWithText:ZQStatusCellContentFont maxW:retweetedContentW];
        self.retweetedContentLabelFrame=CGRectMake(retweetedContentX, retweetedContentY, retweetedContentSize.width, retweetedContentSize.height);
        
        /** 转发配图 */
        CGFloat retweeteH=0;
        NSInteger  retweetedphotosCount = retweeted_status.pic_urls.count;
        if (retweeted_status.pic_urls.count) {//有配图
            CGFloat  retweetepicturesX =retweetedContentX;
            CGFloat  retweetepicturesY = CGRectGetMaxY(self.retweetedContentLabelFrame)+ZQStatusCellBorderWL;
//            CGFloat  retweetepictureW=100;
//            CGFloat  retweetepictureH=100;
            CGFloat  retweetepicturesW=[ZQStatusPhotosView photosviewSizeWithCount:retweetedphotosCount].width;
            CGFloat  retweetepicturesH=[ZQStatusPhotosView photosviewSizeWithCount:retweetedphotosCount].height;
            self.retweetedphotosViewFrame=CGRectMake(retweetepicturesX, retweetepicturesY, retweetepicturesW, retweetepicturesH);
            
            retweeteH=CGRectGetMaxY(self.retweetedphotosViewFrame)+ZQStatusCellBorderW;
        }else
        {
            retweeteH=CGRectGetMaxY(self.retweetedContentLabelFrame)+ZQStatusCellBorderW;
        }
        /** 转发微博容器 */
        CGFloat  retweetViewX=0;
        CGFloat  retweetViewY=CGRectGetMaxY(self.originalViewFrame);
        CGFloat  retweetViewW=cellW;
        CGFloat  retweetViewH=retweeteH+ZQStatusCellBorderW;
        self.retweetedViewFrame=CGRectMake(retweetViewX, retweetViewY, retweetViewW, retweetViewH);
        toolbarY=CGRectGetMaxY(self.retweetedViewFrame);
        
    }else
    {
        //没有转发微博的Cell高度
        toolbarY=CGRectGetMaxY(self.originalViewFrame);
    }
    /** 工具条 */
    CGFloat toolbarX=0;
    CGFloat toolbarW=cellW;
    CGFloat toolbarH=35;
    
    self.toolbarFrame=CGRectMake(toolbarX, toolbarY, toolbarW, toolbarH);
    
    //cel的高度  ＝  toolbarY的最大
    self.cellHeight=CGRectGetMaxY(self.toolbarFrame) + ZQStatusCellBorderWL+5;
    //根据数据设置子控件的frame
}
@end
